package cn.cloudbae.schedule;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;

import cn.cloudbae.kit.PortKit;

public class FirstSimpleJob implements SimpleJob{
    
	@Override
	public void execute(ShardingContext context) {
		
//		String jobName = context.getJobName(); //thirdSimpleJob 在创建job-bean时设置
//		String jobParameter = context.getJobParameter(); //(0=比亚迪,1=长安,2=吉利) parameter是比亚迪/长安/吉利
//		int shardingItem = context.getShardingItem(); //(0=比亚迪,1=长安,2=吉利) item=0/1/2
//		int shardingTotalCount = context.getShardingTotalCount(); //分片总数，在创建job-bean时设置 (0=比亚迪,1=长安,2=吉利,3=大众,4=宝马,5=奔驰,6=福特) count=7
		
		String port = String.valueOf(PortKit.getPort()); //获得运行时端口
		String portTail = port.substring(port.length()-1, port.length());
		if(portTail.equals(String.valueOf(context.getShardingItem()))) { //模拟业务处理
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			String now = sdf.format(new Date());
	        
	        System.out.println(now + " at　" +port + ", " + context.toString());
		}
	}
}
